﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.SysBasic
{
    public partial class OUserEdit : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get { return "OUserList"; }
        }

        #region
        /// <summary>
        /// 需要修改的用户ID
        /// </summary>
        protected int UserId
        {
            get
            {
                return GetRequestValue<int>("UserId");
            }
        }

        private OUserInfo _obj;
        protected OUserInfo obj
        {
            get
            {
                if (_obj == null)
                    _obj = OUserController.GetById(UserId);
                return _obj;
                //OMenuController.ge
            }
        }
        protected string GetRoleList()
        {
            string perhtml = "";
            string peritemtemp = "<option value=\"{0}\" {2}>{1}</option>";
            DataTable alltop = ORoleController.GetAll();
            // string item;
            perhtml = "";
            foreach (DataRow item in alltop.Rows)
            {
                perhtml = perhtml + string.Format(peritemtemp, item["RoleId"], item["RoleName"], obj.RoleId == Convert.ToInt32(item["RoleId"])?"selected":"");
            }
            return perhtml;
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "edituser")
            {
                addmenu();
            }
        }

        protected void addmenu()
        {
            OUserInfo obj2 = Request.SerializableObject<OUserInfo>();
            
            //if (OUserController.CheckUserName(obj.UserName))
            //{
            //    AlertJson("登陆帐户名已存在,请重新输入.");
            //    return;
            //}


            if (OUserController.Update(obj2))
                SuccessJson("修改成功");
            else
                ErrorJson("修改失败");
        }
    }
}